export const editFormConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '配送人员',
			prop: 'riderId',
			propName: 'rider',
			type: 'autoSelect',
			api: 'view_omBusinessPractitioners_page',
			filterKey: 'idCard',
			filterLabel: 'practitionersName',
			paramsObj: {
				belongProject: 'elderlyMeal',
			},
			multiple: false,
			rules: [{ required: true, message: '请选择配送人员' }],
			change: (item, form) => {
				form.riderPhone = item.phone
			},
			span: 24,
		},
	],
}

export const cancelFormConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '取消配送原因',
			prop: 'reason',
			type: 'textarea',
			span: 24,
			rules: [{ required: true, message: '请输入取消配送原因' }],
		},
		{
			label: '取消照片',
			prop: 'cancelPic',
			type: 'upload',
			showFileList: true,
			limit: 4,
			multiple: true,
			rules: [{ required: true, message: '请上传取消照片' }],
			span: 24,
		},
	],
}

export const detailConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '服务组织所在地区',
			prop: 'orgArea',
			span: 8,
		},
		{
			label: '服务组织名称',
			prop: 'orgName',
			span: 8,
		},
		{
			label: '配送工单编号',
			prop: 'orderNo',
			span: 8,
		},
		{
			label: '老人姓名',
			prop: 'objectName',
			span: 8,
		},
		{
			label: '老人联系方式',
			prop: 'phone',
			span: 8,
		},
		{
			label: '订餐时间',
			prop: 'orderTime',
			span: 8,
		},
		{
			label: '订餐配送时间',
			prop: 'deliveryTime',
			span: 8,
		},
		{
			label: '配送人姓名',
			prop: 'rider',
			span: 8,
		},
		{
			label: '配送人联系方式',
			prop: 'riderPhone',
			span: 8,
		},
		{
			label: '配送地址',
			prop: 'address',
			span: 8,
		},
		{
			label: '配送状态',
			prop: 'state',
			custome: 'tag',
			span: 8,
			control: (e, model) => {
				return {
					cancelTime: {
						display: e == 3,
					},
					cancelPic: {
						display: e == 3,
					},
					reason: {
						display: e == 3,
					},
					arrivalTime: {
						display: e == 4,
					},
					pic: {
						display: e == 4,
					},
				}
			},
			dicData: [
				{
					label: '待分配',
					value: 0,
					type: 'warning',
				},
				{
					label: '待配送',
					value: 1,
					type: 'warning',
				},
				{
					label: '配送中',
					value: 2,
					type: 'primary',
				},
				{
					label: '取消配送',
					value: 3,
					type: 'danger',
				},
				{
					label: '已送达',
					value: 4,
					type: 'success',
				},
			],
		},
		{
			label: '取消配送原因',
			prop: 'reason',
			span: 24,
		},
		{
			label: '取消时间',
			prop: 'cancelTime',
			span: 8,
		},
		{
			label: '取消照片',
			prop: 'cancelPic',
			custome: 'file',
			span: 16,
		},
		{
			label: '送达时间',
			prop: 'arrivalTime',
			span: 8,
		},
		{
			label: '送达照片',
			prop: 'pic',
			custome: 'file',
			span: 16,
		},
		{
			label: '菜品套餐信息',
			prop: 'omOrderItemList',
			custome: 'table',
			column: [
				{ label: '名称', prop: 'itemName' },
				{
					label: '类型',
					prop: 'itemType',
					custome: 'tag',
					dicData: [
						{ label: '套餐', value: 1, type: 'success' },
						{ label: '菜品', value: 0, type: 'primary' },
					],
				},
				{ label: '数量', prop: 'num' },
				{ label: '单价', prop: 'price' },
				{ label: '总价', prop: 'totalPrice' },
			],
			span: 24,
		},
	],
}

export const formConfig = (type) => {
	let formColumn = [
		{
			label: '选择老人',
			prop: 'objectId',
			propName: 'objectName',
			type: 'autoSelect',
			api: 'view_omBusinessServiceObject_page',
			filterKey: 'idCard',
			filterLabel: 'name',
			paramsObj: {
				belongProject: 'elderlyMeal',
			},
			multiple: false,
			rules: [{ required: true, message: '请选择选择老人' }],
			span: 12,
			change: (item, form) => {
				form.phone = item.telephone
			},
		},
		{
			label: '订餐类型',
			prop: 'orderType',
			type: 'radio',
			defaultValue: type,
			disabled: true,
			dicData: [
				{
					label: '堂食',
					value: 0,
				},
				{
					label: '配送',
					value: 1,
				},
			],
			rules: [{ required: true, message: '请选择订餐类型' }],
			span: 12,
			control: (e) => {
				return {
					address: {
						display: e == 1,
					},
				}
			},
		},
		{
			label: type == 0 ? '订餐时间' : '订餐配送时间',
			prop: 'orderTime',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			type: 'date',
			span: type == 0 ? 24 : 12,
			rules: [{ required: true, message: `请选择时间` }],
			disabledDate: (date) => {
				let now = new Date().getTime()
				let other = date.getTime()
				return other < now - 1000 * 60 * 60 * 24
			},
		},
		{
			label: '添加配送地点',
			prop: 'address',
			maxlength: '140',
			showWordLimit: true,
			type: 'text',
			display: false,
			span: 12,
			rules: [{ required: true, message: '选择配送具体地址信息' }],
		},
		{
			type: 'DividerHtml',
			position: 'center',
			modelValue: '',
			custome: 'divider',
			span: 24,
		},
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '选择菜品或套餐',
			span: 24,
		},
		{
			label: '',
			prop: 'orderItemVOList',
			type: 'input',
			span: 24,
		},
	]
	return {
		inline: false,
		showBtn: true,
		labelPosition: 'top',
		labelWidth: '120px',
		column: formColumn,
	}
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '服务组织所在地区',
			prop: 'unitAreas',
			propName: 'unitAreasName',
			regionGrade: 3,
			checkStrictly: false,
			type: 'AplidAreaSelect',
			span: 8,
		},
		{ label: '配送工单编号', prop: 'orderNo', span: 8, type: 'input' },
		{ label: '服务组织名称', prop: 'orgName', span: 8, type: 'input' },
		{ label: '老人姓名', prop: 'objectName', span: 8, type: 'input' },
		{ label: '联系方式', prop: 'phone', span: 8, type: 'input' },
		{
			label: '订餐时间',
			prop: 'orderTimeBetween',
			type: 'dateBetween',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
		{ label: '配送人', prop: 'rider', span: 8, type: 'input' },
		{
			label: '配送状态',
			prop: 'state',
			type: 'select',
			dicData: [
				{
					label: '待分配',
					value: 0,
					type: 'warning',
				},
				{
					label: '待配送',
					value: 1,
					type: 'warning',
				},
				{
					label: '配送中',
					value: 2,
					type: 'primary',
				},
				{
					label: '取消配送',
					value: 3,
					type: 'danger',
				},
				{
					label: '已送达',
					value: 4,
					type: 'success',
				},
			],
			span: 8,
		},
		{
			label: '送达时间',
			prop: 'arrivalTimeBetween',
			span: 8,
			type: 'dateBetween',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '服务组织所在地区', prop: 'orgArea' },
		{ label: '配送工单编号', prop: 'orderNo' },
		{ label: '服务组织名称', prop: 'orgName' },
		{ label: '老人姓名', prop: 'objectName' },
		{ label: '联系方式', prop: 'phone' },
		{ label: '菜品/套餐名称', prop: 'mealName' },
		{ label: '价格/元', prop: 'price' },
		{ label: '订餐时间', prop: 'orderTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 100,
			fixed: 'right',
		},
	],
}

export const tableConfig1 = {
	stripe: true,
	border: true,
	columns: [
		{ label: '服务组织所在地区', prop: 'orgArea', width: 100 },
		{ label: '配送工单编号', prop: 'orderNo', width: 250 },
		{ label: '服务组织名称', prop: 'orgName', width: 200 },
		{ label: '老人姓名', prop: 'objectName', width: 120 },
		{ label: '联系方式', prop: 'phone', width: 120 },
		{ label: '菜品/套餐名称', prop: 'mealName', width: 120 },
		{ label: '价格/元', prop: 'price', width: 100 },
		{ label: '订餐时间', prop: 'orderTime', width: 100 },
		{ label: '配送人', prop: 'rider', width: 100 },
		{ label: '配送人联系方式', prop: 'riderPhone', width: 120 },
		{ label: '配送地址', prop: 'address', width: 120 },
		{
			label: '配送状态',
			prop: 'state',
			custome: 'tag',
			dicData: [
				{
					label: '待分配',
					value: 0,
					type: 'warning',
				},
				{
					label: '待配送',
					value: 1,
					type: 'warning',
				},
				{
					label: '配送中',
					value: 2,
					type: 'primary',
				},
				{
					label: '取消配送',
					value: 3,
					type: 'danger',
				},
				{
					label: '已送达',
					value: 4,
					type: 'success',
				},
			],
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}
export const api = {
	index: 'view_omOrder_page',
	add: 'view_omOrder_add',
	edit: 'view_omOrder_edit',
	delete: 'view_omOrder_del',
	detail: 'view_omOrder_view',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '订单配送',
	dictcodes: [],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'objectName',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	menuBtn: [
		{
			icon: '',
			label: '开始分配',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
			condition: (row) => {
				return row.state == 0 && row.orderType == 1
			},
		},
		{
			icon: '',
			label: '重新分配',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
			condition: (row) => {
				return row.state == 1 && row.orderType == 1
			},
		},
		{
			icon: '',
			label: '取消配送',
			type: 'danger',
			operate: 'cancel',
			auth: auth.delete,
			text: true,
			show: true,
			condition: (row) => {
				return (row.state == 1 || row.state == 0) && row.orderType == 1
			},
		},
		{
			icon: '',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],

	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			resolve(form)
		})
	},
	beforeOnLoadFormate: async (params) => {
		if (params.unitAreasName) {
			const tempArea = params.unitAreasName.split('/')
			params.orgArea = tempArea[tempArea.length - 1]
		}
		const queryObj = {
			...params,
			unitAreas: undefined,
			unitAreasName: undefined,
		}
		return Promise.resolve(queryObj)
	},
	onLoadFormate: async (arr) => {
		return new Promise((resolve, reject) => {
			resolve(arr)
		})
	},
	dialogConfig: {
		width: '75%',
	},
	searchConfig,
	formConfig,
	detailConfig,
}
